<template>
  <div>
    <HmPage pageTitle="面经注册" pageButton="注册" type="primary"
    @login="handleLogin"
    ></HmPage>
    <van-nav-bar right-text="有账号,去登录" @click-right="$router.back()"></van-nav-bar>
    <router-view></router-view>
  </div>
</template>

<script>
import axios from 'axios';
import HmPage from '@/components/HmPage.vue';

export default {
    components:{
        HmPage,
        
    },
    methods:{
       async handleLogin(user,pass){
        // console.log(user,pass)
            try{
                const res =await axios({
                url:'http://interview-api-t.itheima.net/h5/user/register',
                method:'post',
                data:{
                    username:user,
                    password:pass
                },
            })
            console.log('注册成功',res.data)
            this.$router.push('/login');
            }
            catch(err){
                console.log('注册失败',err)
                alert('注册失败，请重试');
            }
        }
    }
}
</script>

<style>

</style>